<template>
    <div class="page-container">
      <h1>舆情评论生成系统</h1>
      
      <div class="data-modules">
        <!-- 配置模块 -->
        <div class="module config-module">
          <h3>⚙️ 生成配置</h3>
          <div class="config-item">
            <label>关键词：</label>
            <input v-model="keywords" placeholder="请输入引导关键词" />
          </div>
          <div class="config-item">
            <label>积极比例：{{ positiveRatio }}%</label>
            <input 
              type="range" 
              v-model="positiveRatio"
              min="0" 
              max="100"
            />
          </div>
          <div class="config-item">
            <label>生成数量：</label>
            <input
              type="number"
              v-model.number="count"
              min="1"
              max="1000"
            />
          </div>
          <button @click="generateComments" class="generate-btn">生成评论</button>
        </div>
  
        <!-- 预览模块 -->
        <div class="module preview-module">
          <h3>📄 生成预览</h3>
          <div class="comment-list">
            <div 
              v-for="(comment, index) in generatedComments"
              :key="index"
              class="comment-item"
              :class="{ positive: comment.sentiment === 'positive' }"
            >
              {{ comment.content }}
            </div>
          </div>
        </div>
  
        <!-- 发布模块 -->
        <div class="module publish-module">
          <h3>🚀 发布设置</h3>
          <div class="platform-select">
            <button
              v-for="platform in platforms"
              :key="platform"
              @click="selectedPlatform = platform"
              :class="{ active: selectedPlatform === platform }"
            >
              {{ platform }}
            </button>
          </div>
          <button @click="handlePublish" class="publish-btn">确认发布</button>
        </div>
      </div>
    </div>
  </template>
  
  <script setup>
  import { ref } from 'vue'
  
  // 响应式数据
  const keywords = ref('')
  const positiveRatio = ref(50)
  const count = ref(10)
  const generatedComments = ref([])
  const platforms = ['微信', '微博', '抖音', '知乎', 'B站']
  const selectedPlatform = ref('微博')
  
  // 生成评论的示例内容
  const sampleComments = {
    positive: [
      '产品体验非常棒，强烈推荐！',
      '服务周到，解决问题效率高',
      '性价比超高，会继续支持'
    ],
    negative: [
      '质量有待提高，不太满意',
      '客服响应速度太慢',
      '和宣传的有差距，失望'
    ]
  }
  
  // 生成评论逻辑
  const generateComments = async () => {
    try {
      // 模拟API调用
      const mockData = Array.from({ length: count.value }).map(() => {
        const isPositive = Math.random() * 100 < positiveRatio.value
        const type = isPositive ? 'positive' : 'negative'
        const content = `${keywords.value} ${sampleComments[type][Math.floor(Math.random() * sampleComments[type].length)]}`
        
        return {
          content,
          sentiment: type,
          timestamp: new Date().toISOString()
        }
      })
      
      generatedComments.value = mockData
    } catch (error) {
      console.error('生成失败:', error)
    }
  }
  
  // 发布处理
  const handlePublish = () => {
    if (!selectedPlatform.value) {
      alert('请选择发布平台')
      return
    }
    alert(`已发布到${selectedPlatform.value}`)
  }
  </script>
  
  <style scoped>
  .page-container {
    padding: 2rem;
    background: #2b2d42;
    min-height: 100vh;
    color: white;
  }
  
  h1 {
    font-size: 2rem;
    margin-bottom: 1.5rem;
    color: #8ecae6;
    text-align: center;
  }
  
  .data-modules {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
  }
  
  .module {
    background: rgba(255, 255, 255, 0.1);
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease;
  }
  
  .module:hover {
    transform: translateY(-5px);
  }
  
  .config-item {
    margin: 1rem 0;
  }
  
  input[type="text"], input[type="number"] {
    width: 100%;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid #8ecae6;
    border-radius: 4px;
    color: white;
  }
  
  .comment-list {
    height: 400px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 1rem;
  }
  
  .comment-item {
    padding: 0.8rem;
    margin: 0.5rem 0;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    border-left: 4px solid #8ecae6;
  }
  
  .comment-item.positive {
    border-left-color: #80ed99;
  }
  
  .platform-select button {
    margin: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid #8ecae6;
    color: white;
    border-radius: 20px;
  }
  
  .platform-select button.active {
    background: #8ecae6;
    color: #2b2d42;
  }
  
  button {
    background: #8ecae6;
    color: #2b2d42;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 20px;
    cursor: pointer;
    transition: opacity 0.3s;
    width: 100%;
    margin-top: 1rem;
  }
  
  button:hover {
    opacity: 0.9;
  }
  
  .generate-btn {
    background: #80ed99;
  }
  
  .publish-btn {
    background: #ffb703;
  }
  </style>